//
//  CYBettingWay.m
//  CaiYun
//
//  Created by 今日信息科技 on 2017/7/17.
//  Copyright © 2017年 今日信息科技. All rights reserved.
//

#import "CYBettingWay.h"
@implementation CYBettingWay
/**
 *@ pragma 根据彩种，不同的一级玩法，二级玩法，返回是否需要显示位级选择按钮  YES--显示  NO--不显示
 */
+ (BOOL)isSelectWeiJiWithIdentifier:(NSString *)identifier{
    NSSet *set = [NSSet setWithObjects:@"ssc_z2_r2",@"ssc_5x_r3",@"ssc_z3_r3",@"ssc_z3_r6", nil];//时时彩 ->二星组选-任二组选复式 || 不定胆-任三一码 || 任选-任三组三 || 任选-任三组六
    return ([set containsObject:identifier])?YES:NO;
}
+ (NSMutableArray *)selectWeiJiArr:(NSString *)identifier{
    if ([identifier isEqualToString:@"ssc_z2_r2"])//时时彩-二星组选-任二组选复式
        return [NSMutableArray arrayWithObjects:@"4",@"3", nil];
    else if ([@[@"ssc_z3_r3",@"ssc_5x_r3",@"ssc_z3_r6"] containsObject:identifier])//时时彩-不定胆-任三一码 |任选-任三组三 | 任三组六
        return [NSMutableArray arrayWithObjects:@"4",@"3",@"2", nil];


    return nil;
}
/**
 *@pragma 任选之类的（多个cell,选一个cell就能中奖）
 */
+ (BOOL)isSpecialLottery:(NSString *)identifier{
    NSSet *set = [NSSet setWithObjects:@"ssc_5x_dw",@"ssc_2x_r2f",@"ssc_3x_r3f",@"ssc_dx_r4f",@"three_dxds_r2",@"three_3x_dw",@"ssc_11x5_dwd",@"bjpk10_dw",@"ssl_dwd_dwd",nil];
    return ([set containsObject:identifier])?YES:NO;
}
/**
 *@ pragma 获取某种彩票的玩法   array:彩种的玩法信息
 */
+ (NSMutableArray *)getBettingWay:(NSArray <CYFirstSubBetModel *>*)array{
    if (!array)
        return nil;
    NSMutableArray *mutableArr = [NSMutableArray array];
    for (CYFirstSubBetModel *firstBetModel in array) {
        NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
        NSMutableArray *secondArr = [NSMutableArray array];
        for (CYSecondSubBetModel *secondBetModel in firstBetModel.seconSubBetArr) {
            NSString *secondName = secondBetModel.name;//二级玩法名称
            [secondArr addObject:secondName];
        }
        NSString *firstName = firstBetModel.groupName;//一级玩法名称
        [mutableDict setValue:secondArr forKey:firstName];
        [mutableArr addObject:mutableDict];
    }
    return [mutableArr mutableCopy];
}

/**
 *@ pragma 数据处理，获取彩票的信息，和当前选中的一级玩法下的二级玩法的信息，并以字典返回
 */
+ (NSMutableDictionary *)getCurrentModel:(CYBetModel *)model firstIndex:(NSUInteger)firstIndex secondIndex:(NSUInteger)secondIndex{
    if (!model)
        return nil;
    NSMutableDictionary *newDict = [NSMutableDictionary dictionary];
    CYFirstSubBetModel *fisrtSubModel = model.firstSubBetArr[firstIndex];
    CYSecondSubBetModel *secondSubModel = fisrtSubModel.seconSubBetArr[secondIndex];
    
    [newDict setValue:model.actionNo forKey:@"actionNo"];//期号
    [newDict setValue:model.actionTime forKey:@"actionTime"];
    [newDict setValue:@(model.endTime) forKey:@"endTime"];
    [newDict setValue:@(model.playedGroupId) forKey:@"playedGroupId"];//
    [newDict setValue:@(model.fanDianMax) forKey:@"fanDianMax"];
    [newDict setValue:@(model.ID) forKey:@"lotteryID"];
    [newDict setValue:model.name forKey:@"lotteryName"];
    
    [newDict setValue:@(fisrtSubModel.ID) forKey:@"firstBetID"];//一级玩法ID
    [newDict setValue:fisrtSubModel.groupName forKey:@"firstBetName"];//一级玩法名称
    
    [newDict setValue:@(secondSubModel.ID) forKey:@"secondBetID"];
    [newDict setValue:@(secondSubModel.maxCount) forKey:@"maxCount"];
    [newDict setValue:@(secondSubModel.minCharge) forKey:@"minCharge"];
    [newDict setValue:@(secondSubModel.selectNum) forKey:@"selectNum"];
    [newDict setValue:secondSubModel.example forKey:@"example"];
    [newDict setValue:secondSubModel.name forKey:@"secondBetName"];
    [newDict setValue:secondSubModel.playedTpl forKey:@"playedTpl"];
    [newDict setValue:secondSubModel.simpleInfo forKey:@"simpleInfo"];

    if (secondSubModel.gatherArr.count > 0)
    [newDict setValue:[CYSecondSubBetModel mj_keyValuesArrayWithObjectArray:secondSubModel.gatherArr] forKey:@"gatherArr"];//模型数组转换成字典数组
    
    [newDict setValue:@(secondSubModel.bonusProp) forKey:@"bonusProp"];
    [newDict setValue:@(secondSubModel.bonusPropBase) forKey:@"bonusPropBase"];
    [newDict setValue:[self getNumbersWithCodeList:model.codeList betWayIdentifier:secondSubModel.playedTpl] forKey:@"codeList"];
    NSString *string = [NSString stringWithFormat:@"%@-%@",fisrtSubModel.groupName, secondSubModel.name];//每个子玩法的名称
    [newDict setValue:[self getRowsOfCell:secondSubModel.playedTpl subPlayName:string] forKey:@"cellArr"];
    return newDict;
}

/**
 *@ pragma 通过唯一标识符"played_tpl"，筛选彩种玩法有多少行
 */
+ (NSArray *)getRowsOfCell:(NSString *)playedTPLString subPlayName:(NSString *)string{
    NSArray *array = [self betWayIdentifierArr];
    for (int i = 0; i < array.count; i ++) {
        if ([array[i] containsObject:playedTPLString])
            return [self weiJiArr][i];
    }
    NSAssert(NO, ([NSString stringWithFormat:@"%@的唯一标识符没有被包含 selector --> (aa:)通过唯一标识符，筛选彩种的位级", playedTPLString]));
    return nil;
}
/**
 *@ pragma 彩票玩法的号码数组
 */
+ (NSArray *)getNumbersWithCodeList:(NSString *)codeListString betWayIdentifier:(NSString *)identifier{
    //    NSString *identifier = identifierDict[@"bet_way"][@"played_tpl"];//彩票玩法标识符
    NSArray *specialArr = [self specialBetWayIdentifier];//特殊玩法标识符
    for (int i = 0; i < specialArr.count ; i ++) {
        if ([specialArr[i] containsObject:identifier]) {//如果包含在特殊玩法内
            return [NSString arrayWithString:[self specialCodeList][i]];//返回特殊的号码
        }
    }
    return [NSString arrayWithString:codeListString];//正常返回号码
}

/**
 * @pragma 特殊玩法下，彩票的号码code_list
 */
+ (NSArray *)specialCodeList{
    return @[@"0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27",
             @"1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26",
             @"3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24",
             @"0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18",
             @"1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17",
             @"3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18",
             @"111,222,333,444,555,666",
             @"11,22,33,44,55,66",
             @"03,04,05,06,07,08,09",
             @"豹子,顺子,对子",
             @"三同号通选",
             @"三连号通选",
             @"龙,虎",
             @"大,小,单,双"];
    
}

/**
 * @pragma 特殊玩法
 */
+ (NSArray *)specialBetWayIdentifier{
    return @[@[@"s3d_hz",@"ssl_3x_zxhz"],// 和值 0 -> 27
             @[@"ssl_3x_z3hz"],//和值 1 -> 26
             @[@"ssl_3x_z6hz"],//和值 3 -> 24
             @[@"ssc_q2_zhi_hz",@"ssc_h2_zhi_hz"],// 和值 0 -> 18
             @[@"ssc_qh2_zhu_hz",@"ssc_h2_zhu_hz"],// 和值 1 -> 18
             @[@"k3_hz"],// 和值 3 -> 18
             @[@"k3_3dx"],//三同单选 111 -> 666
             @[@"k3_2fx",@"k3_2dx"], //二同号复选 11 -> 66
             @[@"qwwf_czw"],//猜中位 03 -> 09
             @[@"ssc_ts_h3"],//豹子,顺子,对子
             @[@"k3_3tx"], //三同号通选
             @[@"k3_3ltx"], //三连号通选
             @[@"pk10_lh"],//龙虎
             @[@"ssc_dxds_q2",@"ssc_dxds_h2",@"ssc_dxds_q3",@"ssc_dxds_h3",@"",@"three_dxds_r2",@"pk10_lm_dxds1",@"ssl_dxds_q2dxds",@"ssl_dxds_h2dxds"]];//大小单双
}

/**
 * @pragma 获取彩票的位级数组
 */
+ (NSArray *)weiJiArr{
    return @[@[@"冠军",@"亚军",@"季军",@"第四名",@"第五名",@"第六名",@"第七名",@"第八名",@"第九名",@"第十名"],//0
             @[@"冠军",@"亚军",@"季军"], //1
             @[@"冠军",@"亚军"], //2
             @[@"冠亚季"], //3
             @[@"万位",@"千位",@"百位",@"十位",@"个位"],   //4
             @[@"万位",@"千位",@"百位",@"十位"],//5
             @[@"千位",@"百位",@"十位",@"个位"],//6
             @[@"万位",@"千位",@"百位"],//7
             @[@"千位",@"百位",@"十位"],//8
             @[@"百位",@"十位",@"个位"],//9
             @[@"万位",@"千位"],//10
             @[@"百位",@"个位"],//11
             @[@"十位",@"个位"],//12
             @[@"二重号",@"单号"],//13
             @[@"三重号",@"单号"],//14
             @[@"三重号",@"二重号"],//15
             @[@"四重号",@"单号"],//16
             @[@"二重号"],//17
             @[@"第一位",@"第二位",@"第三位",@"第四位",@"第五位"], //18
             @[@"第一位",@"第二位",@"第三位"], //19
             @[@"第一位",@"第二位",], //20
             @[@"和值选号"],//21
             @[@"特殊号"],//22
             @[@"同号",@"不同号"],//23
             @[@"猜中位"],//24
             @[@"号码"]];//25
}

/**
 *@ pragma 彩票玩法的唯一标识符
 */
+ (NSArray *)betWayIdentifierArr{
    return @[ @[@"bjpk10_dw"],//0  冠军->第十名
              @[@"bjpk10_x3"],//1  冠军->季军
              @[@"bjpk10_x2"],//2  冠军,亚军
              @[@"pk10_x1"],//3  冠亚季
              @[@"ssc",@"ssc_5x_dw",@"ssc_2x_r2f",@"ssc_3x_r3f",@"ssc_dx_r4f"],//4 万位->个位
              @[@"ssc_dx_q4f"],//5 万位->十位
              @[@"ssc_dx_h4f"],//6 千位->个位
              @[@"ssc_3x_q3f",@"ssc_dxds_q3"],//7 万位->百位
              @[@"ssc_3x_z3fs"],//8  千位->十位
              @[@"ssc_3x_h3f",@"ssc_dxds_h3",@"ssl_3x_3zxf",@"three_dxds_r2",@"three_3x_dw",@"ssl_dwd_dwd"],//9   百位->个位
              @[@"ssc_2x_q2f",@"ssc_dxds_q2"],//10  万位,千位
              @[@"ssl_2x_q2zxf",@"ssl_dxds_q2dxds",@"three_2x_q2f"],//11  百位,十位
              @[@"ssc_2x_h2f",@"ssc_dxds_h2",@"ssl_2x_h2zxf",@"ssl_dxds_h2dxds"],//12  十位,个位
              @[@"ssc_5x_z5_60",@"ssc_5x_z5_30",@"ssc_4x_z4_12"],//13 二重号，单号
              @[@"ssc_5x_z5_20",@"ssc_4x_z4_4"],//14 三重号,单号
              @[@"ssc_5x_z5_10"],//15 三重号,二重号
              @[@"ssc_5x_z5_5"],//16  四重号, 单号
              @[@"ssc_4x_z4_6"],//17  二重号
              @[@"ssc_11x5_dwd"],//18 第一位->第五位
              @[@"s115_q3_zhi"],//19 第一位->第三位
              @[@"s115_q2_zhi"],//20 第一位,第二位
              @[@"ssc_q2_zhi_hz",@"ssc_h2_zhi_hz",@"ssc_qh2_zhu_hz",@"ssc_h2_zhu_hz",@"ssl_3x_zxhz",@"k3_hz",@"s3d_hz"],//21 和值选号
              @[@"ssc_ts_h3"],//22 特殊号
              @[@"k3_2dx"],//23 同号,不同号
              @[@"qwwf_czw"],//24 猜中位
              @[@"ssc_5x_z5_120",@"ssc_4x_z4_24",@"ssc_h3_kd",@"ssc_hz_h3",@"ssc_z3_q3",@"ssc_z3_q6",@"ssc_z3_z3",@"ssc_z3_z6",
                @"ssc_z2_f2",@"ssc_z2_r2",@"ssc_5x_q3",@"ssc_5x_z3",@"ssc_5x_h3", @"ssc_5x_r3",@"ssc_2x_qbdw",@"ssc_2x_hbdw",
                @"ssc_5x_3m_bdw",@"ssc_5x_2m_bdw", @"ssc_4x_2m_bdw",@"ssc_4x_1m_bdw",@"ssc_z3_r3",@"ssc_z3_r6",@"qwwf_yffs",
                @"s115_q2_zu",@"s11x5_q1z",@"s115_q3_zu",@"ssc_11x5_bdw",@"s115_rx1",@"s115_rx2",@"s115_rx3",@"s115_rx4",
                @"s115_rx5",@"s115_rx6",@"s115_rx7",@"s115_rx8",@"ssl_3x_z3f",@"ssl_3x_z3hz",@"ssl_3x_z6hz",@"ssl_2x_q2zf",
                @"ssl_2x_h2zf",@"ssl_bdw_1mbdw",@"ssl_bdw_2mbdw",@"pk10_lm_dxds1",@"pk10_lh",@"k3_3dx",@"k3_3tx",@"k3_3ltx",
                @"k3_3x",@"k3_2fx",@"k3_2x",@"ssc_2x_bdw",]];//25 号码
}
//把数组的元素，由字符串转换成字典
+ (NSArray *)arrayWithArray:(NSArray *)array{
    
    NSMutableArray *newArr = [NSMutableArray array];
    for (int i = 0; i < array.count; i ++) {
        [newArr addObject:@{@"title":array[i]}];
    }
    return newArr;
}
@end
